<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <script th:src="@{/}+'js/tool.js'"></script>
    <style type="text/css">
        .layui-form .layui-form-item{
            width:90%;
        }
        .layui-input-inline{
            width:350px!important
        }
    </style>

</head>
<body style="margin-top: 100px">
<form class="layui-form" lay-filter="myform" id="myform">
    <input type="hidden" name="id" id="id" th:value="${id}">
    <input type="hidden" name="delFlag" id="delFlag" value="1">
    <div class="layui-form-item">
        <label class="layui-form-label">章名称</label>
        <div class="layui-input-inline">
            <input type="text" name="name" lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">篇</label>
        <div class="layui-input-inline">
            <select name="pianId" id="pianId"></select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-inline">
            <input type="number" name="orderno" id="orderno" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">登记人</label>
        <div class="layui-input-inline">
            <input type="text" name="createUserName" id="createUserName" th:value="${session.me.name}" readonly="readonly" class="layui-input">
            <input type="hidden" name="createUserId" id="createUserId" th:value="${session.me.id}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">登记时间</label>
        <div class="layui-input-inline">
            <input type="text" name="createTime" id="createTime" th:value="${currentTime}" readonly="readonly" class="layui-input">
        </div>
    </div>
    <button id="submitBtn" class="layui-btn" style="display:none" lay-submit lay-filter="submitme">保存</button>
</form>

<script>
    var id = $("#id").val();

    layui.use(['form', 'table', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
        select('pian/getPageList?limit=30&page=1' , 'pianId',form,'name','id')
        form.on('submit(submitme)', function(data){
            var values = {};
            $(":input").each(function(i,v){
                if(v.name){
                    if(v.name){
                        values[v.name] = v.value;
                    }
                }
            })
            axios.post("chapter/save",values).then(res=>{
                if(res.data.code==1){
                    layer.msg(ret.msg);
                }else{
                    let win = getTabWin();
                    win.loadGrid("main-table");
                    layer.msg("保存成功");
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                }
            })
            return false;
        });
        if(id){
            loadData()
        }else{
            let pianId = `[[${pianId}]]`;
            $("#pianId").val(pianId)
            form.render();
        }
        function loadData(){
            var entity = getEntityInfo(id,"chapter/getById");
            form.val("myform",entity);
        }

    })
</script>
</body>
</html>

</body>
</html>